<?php

namespace App\Http\Requests\MCategory;

use App\Http\Requests\BaseRequest;
use App\Models\GoodsCategory;

class AddRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'    => 'required|min:1|max:8|unique:goods_categories,name',
            'is_show' => 'required|in:' . GoodsCategory::IS_SHOW_NO . ',' . GoodsCategory::IS_SHOW_YES,
            'status'  => 'required|in:' . GoodsCategory::STATUS_NO . ',' . GoodsCategory::STATUS_YES,
            'pid'     => 'integer',
            'sequence' => 'required|integer|min:0',
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '请填写名称',
            'name.unique' => '名称已存在',
            'name.min' => '名称不能少于1个字符',
            'name.max' => '名称不能超过8个字符',
            'is_show.required' => '请选择是否展示',
            'is_show.in' => '所选是否展示不在范围内',
            'status.required' => '请选择状态',
            'status.in' => '所选状态不在范围内',
            'sequence.required' => '请填写排序',
            'sequence.min' => '排序值不能小于0',
        ];
    }
}
